//
//  WBTitleButton.swift
//  weibo
//
//  Created by Felix on 16/11/6.
//  Copyright © 2016年 Felix. All rights reserved.
//

import UIKit

class WBTitleButton: UIButton {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setUI()
    }
    
    
    private func setUI(){
        setImage(#imageLiteral(resourceName: "navigationbar_arrow_down"), for: .normal)
        setImage(#imageLiteral(resourceName: "navigationbar_arrow_up"), for: .selected)
        
        setTitleColor(UIColor.darkGray, for: .normal)
        setTitleColor(UIColor.orange, for: .selected)
        
        sizeToFit()
    }
    
    
    //??这个是对可选值类型进行解包、如果有值则使用解包出来的值 如果没有则用后面传入的值
    override func setTitle(_ title: String?, for state: UIControlState) {
        super.setTitle((title ?? "")+"  ", for: UIControlState.normal)
    }
    
    open override func layoutSubviews() {
        super.layoutSubviews()
        ///1.调整title的位置为左边
        titleLabel?.frame.origin.x = 0
        ///2.调整image的位置为紧邻title
        imageView?.frame.origin.x = (titleLabel?.frame.size.width)!
    }
}
